<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div id="test"></div>
  <div id="test1"></div>
  <div id="test2"></div>

  <script type="text/javascript" src="../js/react.development.js"></script>
  <script type="text/javascript" src="../js/react-dom.development.js"></script>
  <script type="text/javascript" src="../js/babel.min.js"></script>
  <script type="text/javascript" src="../js/prop-types.js"></script>
  <script type="text/babel">
    class MyComponent extends React.Component{
        static propTypes={
        name:PropTypes.string.isRequired,
        age:PropTypes.number,
        sex:PropTypes.string,
        speak:PropTypes.func
        }
        static defaultProps={
            sex:'不知男女',
            age:18
        }
        render(){
            const {name,age,sex} = this.props
            return (
                <ul>
                    <li>姓名：{name}</li>
                    <li>年龄：{age+1}</li>
                    <li>性别:{sex}</li>
                </ul>
            )
        }
    }
    
    ReactDOM.render(<MyComponent name='wtt' age={18} sex='男' speak={speak}/>,document.getElementById('test'))
    ReactDOM.render(<MyComponent name='typ' age={19}/>,document.getElementById('test1'))
    const obj = {name:'wt',sex:'女'}
    ReactDOM.render(<MyComponent {...obj}/>,document.getElementById('test2'))

    function speak(){
        console.log('我说话了');
    }
  </script>
</body>

</html>